package cn.hx.mall.goods.service.impl;

import cn.hx.mall.goods.dao.ProductCategoryAttributeRelationDao;
import cn.hx.mall.goods.entity.ProductCategoryAttributeRelation;
import cn.hx.mall.goods.service.ProductCategoryAttributeRelationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 产品的分类和属性的关系表，用于设置分类筛选条件（只支持一级分类）(ProductCategoryAttributeRelation)表服务实现类
 *
 * @author makejava
 * @since 2022-11-02 15:58:01
 */
@Service("productCategoryAttributeRelationService")
public class ProductCategoryAttributeRelationServiceImpl implements ProductCategoryAttributeRelationService {
    @Resource
    private ProductCategoryAttributeRelationDao productCategoryAttributeRelationDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ProductCategoryAttributeRelation queryById(Long id) {
        return this.productCategoryAttributeRelationDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<ProductCategoryAttributeRelation> queryAllByLimit(int offset, int limit) {
        return this.productCategoryAttributeRelationDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param productCategoryAttributeRelation 实例对象
     * @return 实例对象
     */
    @Override
    public ProductCategoryAttributeRelation insert(ProductCategoryAttributeRelation productCategoryAttributeRelation) {
        this.productCategoryAttributeRelationDao.insert(productCategoryAttributeRelation);
        return productCategoryAttributeRelation;
    }

    /**
     * 修改数据
     *
     * @param productCategoryAttributeRelation 实例对象
     * @return 实例对象
     */
    @Override
    public ProductCategoryAttributeRelation update(ProductCategoryAttributeRelation productCategoryAttributeRelation) {
        this.productCategoryAttributeRelationDao.update(productCategoryAttributeRelation);
        return this.queryById(productCategoryAttributeRelation.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.productCategoryAttributeRelationDao.deleteById(id) > 0;
    }
}